<?php

namespace App\Http\Controllers\Admin;

use App\Replies as RepliesModel;
use \Request;

class Replies extends Base
{

    public function index()
    {
        $articleID   = Request::get('article_id');
        $repliesList = RepliesModel::orderBy('id', 'desc')
            ->where('article_id', '=', $articleID)
            ->paginate(15);

        $count = RepliesModel::where('article_id', '=', $articleID)->count();
        return view('admin.replies.index', [
            'repliesList' => $repliesList,
            'count'       => $count,
        ]);
    }

    public function edit($id = '')
    {
        $repliesInfo = RepliesModel::find($id);
        return view('admin.replies.edit', [
            'info' => $repliesInfo,
        ]);
    }

    public function update($id = '')
    {
        $result = RepliesModel::where('id', '=', $id)->update([
            'admin_content' => Request::input('admin_content', ''),
        ]);
        return $result ? showSuccess('编辑回复贴子成功！') : showError('编辑回复贴子失败！');
    }

    public function destroy($id = '')
    {
        $result = RepliesModel::where('id', '=', $id)->delete();
        return $result ? showSuccess('删除回复贴子成功！') : showError('删除回复贴子失败！');
    }
}
